package kitty.main;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.kittyvszombie.R;

public class FoodKitty extends Kitty {
	private ArrayList<Enemy> enemies;
	private Bitmap kittyImage2, kittyImage3;
	private int foodLeft = 2;

	public FoodKitty(MainView view, int row, float x, float y) {
		this.view = view;
		this.row = row;
		enemies = view.getEnemies();
		projectiles = view.getProjectiles();
		stars = view.getStars();
		this.x = x - 20;
		this.y = y - 30;

		kittyImage = BitmapFactory.decodeResource(view.getResources(),
				R.drawable.foodkitty);
		kittyImage2 = BitmapFactory.decodeResource(view.getResources(),
				R.drawable.foodkitty2);
		kittyImage3 = BitmapFactory.decodeResource(view.getResources(),
				R.drawable.foodkitty3);
		deadImage = BitmapFactory.decodeResource(view.getResources(),
				R.drawable.foodkitty_dead);
		rateOfFire = 20.0f;
		image = kittyImage;
	}

	@Override
	public void update() {

		if (view.isEnemyOnRow(row) && !dead) {
			for (int i = 0; i < enemies.size(); i++) {
				if (enemies.get(i).getId() == getRow()
						&& !enemies.get(i).getWalkback()
						&& x + image.getWidth() > enemies.get(i).getX()
						&& x + image.getWidth() < enemies.get(i).getX()
								+ enemies.get(i).getEnemyImages()[0].getWidth()) {
					if (foodLeft > 0)
						enemies.get(i).walkback();
					foodLeft--;
					updateFoodKitty();
				}
			}
		}
	}

	private void updateFoodKitty() {
		switch (foodLeft) {
		case -1:
			this.kill();
			break;

		case 1:
			image = kittyImage2;
			break;
		case 0:
			image = kittyImage3;
			break;

		}
	}
}